"use strict";
/**
 * 根据权限控制访问方法
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
{
    const userState = {
        username: 'Jimmy',
        isLogin: true,
        power: ['store'], // 权限列表
    };
    const AccessCross = (powerList) => {
        return (target, propertyKey, descriptor) => {
            const method = descriptor.value;
            const validate = () => {
                /**
                 * 验证方法 -- 判断一个数组中是否含有另外的数组
                 *  这里使用了数组的 every方法  every方法返回的是布尔值 会每个值都遍历一遍 都为true 才会为true
                 */
                return powerList.every(item => userState.power.includes(item));
            };
            descriptor.value = () => {
                if (userState.isLogin && validate()) {
                    method();
                    return;
                }
                console.log('权限不足');
            };
        };
    };
    class User {
        /**
         * 保存文章需要登录才能操作
         */
        store() {
            console.log('保存文章');
        }
        watch() {
            console.log('阅读文章');
        }
    }
    __decorate([
        AccessCross(['store']),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", []),
        __metadata("design:returntype", void 0)
    ], User.prototype, "store", null);
    new User().store();
}
